import { StatusBar } from "expo-status-bar";
import { useReducer } from "react";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import Loading from "./components/Loading";
import { GlobalContext, reducer, state as initState } from "./hooks/reducer";
import useCachedResources from "./hooks/useCachedResources";
import useColorScheme from "./hooks/useColorScheme";
import Navigation from "./navigation";
import "react-native-gesture-handler";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { ToastProvider } from "react-native-toast-notifications";
export default function App() {
  const isLoadingComplete = useCachedResources();
  const colorScheme = useColorScheme();
  const [state, dispatch] = useReducer(reducer, initState);

  if (!isLoadingComplete) {
    return null;
  } else {
    return (
      //SafeAreaProvider 开启苹果安全区域适配
      //Navigation导航屏幕展示
      <GestureHandlerRootView style={{ flex: 1 }}>
        <GlobalContext.Provider value={{ state, dispatch }}>
          <SafeAreaProvider style={{ flex: 1, backgroundColor: "#fff" }}>
            {/* 黑夜模式 */}
            {/* <Navigation colorScheme={colorScheme} /> */}
            {state.isActivityIndicator && <Loading />}
            <ToastProvider
              animationType="slide-in"
              duration={3000}
              textStyle={{ fontSize: 16}}
              offsetBottom={40}
              offsetTop={40}
              offset={20}
              style={{elevation:222,zIndex:999}}
            >
              <Navigation />
            </ToastProvider>

            <StatusBar style="dark" />
          </SafeAreaProvider>
        </GlobalContext.Provider>
      </GestureHandlerRootView>
    );
  }
}
